﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SJointFunc : SFuncBase
{
    private HingeJoint2D RigidComp
    {
        get => GetComponent<SSwingJoint>().rigidComp;
    }
    public float MotorSpeed=60;
    public override void LocalKeyOn()
    {
        base.LocalKeyOn();
        RigidComp.useLimits = false;
        var motor = RigidComp.motor;
        motor.motorSpeed = MotorSpeed;
        RigidComp.motor = motor;
        Debug.Log(RigidComp.motor.motorSpeed + " " + RigidComp.useLimits);
    }
    void SetLimit(float angle)
    {
        RigidComp.useLimits = true;
        RigidComp.limits = new JointAngleLimits2D { min = angle, max = angle };
    }
    public override void LocalKeyUp()
    {
        base.LocalKeyUp();
        var motor = RigidComp.motor;
        motor.motorSpeed = 0;
        RigidComp.motor = motor;
        SetLimit(RigidComp.jointAngle);
    }
}